160B - Unlucky Ticket - CodeForces Solution


greedy sortings *1100

Please click on ads to support us..

Python Code:

n=int(input())

s=input()

erste=[]
erstet=0
zweite=[]
zweitet=0

for i in range(n):
    erste.append(int(s[i]))
    erstet+=int(s[i])

for i in range(n,2*n):
    zweite.append((int(s[i])))
    zweitet+=int(s[i])

flag=0

first=sorted(erste)
second=sorted(zweite)


if zweitet>erstet:
    for i in range(n):
        if(first[i]>=second[i]):
            print("NO")
            flag=1
            break

    if(flag==0):
        print("YES")

elif zweitet<erstet:

    for i in range(n):
        if (first[i] <= second[i]):
            print("NO")
            flag = 1
            break

    if (flag == 0):
        print("YES")

else:
    print("NO")

C++ Code:

// white ربِّ زِدْن
#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/assoc_container.hpp>//common file for PBDS
#include<ext/pb_ds/tree_policy.hpp> //including tree_order_statistics_node_update
using namespace __gnu_pbds; //namespace
#define ordered_set tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> //macro definition

#define debug(...) cerr << "[" << #__VA_ARGS__ << "] =>", dbg_out(__VA_ARGS__)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type >
ostream & operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Up, typename... Down> void dbg_out(Up U, Down... D) { cerr << ' ' << U; dbg_out(D...); }

#define int long long int
#define ll long long
#define ss second
#define ff first
#define pb push_back
#define ppb pop_back
#define pf push_front
#define mkp make_pair
#define PI 3.1415926536
#define setp setprecision
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
#define Yes cout<<"YES"<<endl;
#define No cout<<"NO"<<endl;
#define bye  continue;
#define edl cout<<endl;
#define all(x) (x).begin(), (x).end()
#define rall(s) s.rbegin(), s.rend()
#define sz(v) ((int)(v).size())
#define az(x) memset(x,0,sizeof(x));
#define eps 1e-7
#define inf LLONG_MAX
#define MOD(a,mod) ( ((a%mod+mod)%mod) < 0 ? ((a%mod+mod)%mod)+mod : ((a%mod+mod)%mod) )
#define tani(a) atan(a)/(pi/180)
#define sini(a) asin(a)/(pi/180)
#define cosi(a) acos(a)/(pi/180)
#define cos(a)  cos(a*pi/180)
#define sin(a)  sin(a*pi/180)
#define tan(a)  tan(a*pi/180)
#define srt(x) sort(x.begin(),x.end())
#define rsrt(x) sort(x.begin(),x.end(),greater<>())
#define torad(x) ((x) * ((2*acos(0))/180.0))
#define todeg(x) ((x) * (180.0/(2*acos(0))))
#define fixAngle(x) ( (x) > 1 ? 1 : (x) < -1 ? -1 : (x))
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define scanm(n,mp) for(i=0;i<n;i++){ll x; cin>>x,mp[x]++;}
#define printv(v) for(i=0;i<sz(v);i++)cout<<v[i]<<' ';edl
#define scanv(n,v) for(i=0;i<n;i++){ll x; cin>>x,v.pb(x);}
#define trzero(x)       __builtin_ctz(x)
#define parity(x)       __builtin_parity(x)
#define countone(x)     __builtin_popcount(x)
bool PRIME(ll p) {if (p <= 1)return false; if (p <= 3)return true; if (p % 2 == 0 || p % 3 == 0) return false; for (int i = 5; p >= i * i; i = i + 6) {if (p % i == 0 || p % (i + 2) == 0) return false;} return true;}
int sum_digit(int x) { int sum = 0; while (x > 0) { sum += x % 10; x /= 10; } return sum; }
ll reverse_num(ll n) { ll tmp = n, ans = 0, r; while (tmp > 0) { r = tmp % 10; ans = ans * 10 + r; tmp /= 10; } return ans; }
ll factorial(ll n) { ll i, ans = 1; for (i = n; i > 1; i--) {ans *= i;} return ans; }
ll to_int(string s) { int len = sz(s); ll ans = 0; for (int i = 0; i < len; i++)ans = ans * 10 + (int)s[i] - '0'; return ans; }
string to_str(ll x) {stringstream ss; ss << x; return ss.str();}
ll todec(string s) {return stoi(s, 0, 2);}
bool ispalin(string s) {bool flag = true; for (int i = 0; i < sz(s) / 2; i++) {if (s[i] != s[sz(s) - 1 - i]) {flag = false; break;}} return flag;}
string toBinary(int n) {string r; while (n != 0) {r = (n % 2 == 0 ? "0" : "1") + r; n /= 2;} return r;}
bool isPowerOfTwo(int n) {if (n == 0)return false; return (ceil(log2(n)) == floor(log2(n)));}
bool issorted(std::vector<int> &v) {for (int i = 0; i < sz(v) - 1; i++)if (v[i] > v[i + 1])return false; return true;}
bool isrsorted(std::vector<int> &v) {for (int i = 0; i < sz(v) - 1; i++)if (v[i] < v[i + 1])return false; return true;}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {return a.second < b.second;}
int binaryToDecimal(int n) {int num = n; int dec{}; int base = 1; int tm = num; while (tm) {int ld = tm % 10; tm = tm / 10; dec += ld * base; base *= 2;} return dec;}
bool isSquare(int x) {int y = sqrt(x); return y * y == x;}
//sort(vect.begin(), vect.end(), sortbysec);
int dx[] = { -1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int dx8[] = { -1, 1, 0, 0, -1, -1, 1, 1};
int dy8[] = {0, 0, -1, 1, -1, 1, -1, 1};
void rTime() {
    cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
}
#define FASTER ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/////////////////////////////////////////////end of tools///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////main//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Prongs();

int32_t main()
{
    FASTER;
    Prongs();
    return 0;
}


void Prongs()
{
	int n; cin>>n;
	string s; cin>>s;

	sort(s.begin(),s.begin()+n);
	sort(s.begin()+n,s.end());
	
	int cnt1{};
	for(int i=0,j=n;i<n;i++,j++)
		if(s[i]<s[j])
			cnt1++;
				
	int cnt2{};
	for(int i=0,j=n;i<n;i++,j++)
		if(s[i]>s[j]) 
			cnt2++;		

	if(cnt1==n or cnt2==n)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}


Comments

Submit
0 Comments
More Questions

1343C - Alternating Subsequence
1325A - EhAb AnD gCd
746A - Compote
318A - Even Odds
550B - Preparing Olympiad
939B - Hamster Farm
732A - Buy a Shovel
1220C - Substring Game in the Lesson
452A - Eevee
1647B - Madoka and the Elegant Gift
1408A - Circle Coloring
766B - Mahmoud and a Triangle
1618C - Paint the Array
469A - I Wanna Be the Guy
1294A - Collecting Coins
1227A - Math Problem
349A - Cinema Line
47A - Triangular numbers
1516B - AGAGA XOOORRR
1515A - Phoenix and Gold
1515B - Phoenix and Puzzle
155A - I_love_username
49A - Sleuth
1541A - Pretty Permutations
1632C - Strange Test
673A - Bear and Game
276A - Lunch Rush
1205A - Almost Equal
1020B - Badge
1353A - Most Unstable Array